import tables

var seen = {1: 0}.toTable

proc steps*(n: int): int =
  if n <= 0:
    raise newException(ValueError, "zero or negative value is an error")

  if n in seen:
    return seen[n]

  result = 1 + steps(if n mod 2 == 0: n div 2 else: 3 * n + 1)
  seen[n] = result